package com.xd.common.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

//初始化数据表
//@Component
//@Order(1)
public class InitDataSourceTable {
//public class InitDataSourceTable implements ApplicationRunner {
//    private static final Logger log = LoggerFactory.getLogger(InitDataSourceTable.class);
//    @Autowired
//    private DataSource dataSource;
//    @Override
//    public void run(ApplicationArguments args){
//        log.info("表文件sql文件初始化开始");
//        // 通过直接读取sql文件执行
//        Resource resources = new ClassPathResource("sql/初始化sql.sql");
//        ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
//        resourceDatabasePopulator.addScripts(resources);
//        resourceDatabasePopulator.execute(dataSource);
//        log.info("表文件sql文件初始化结束");

}
